package com.commerceE.common.dao;

import org.mybatis.spring.support.SqlSessionDaoSupport;


public abstract class GenericIBatisDaoImpl<T> extends SqlSessionDaoSupport
		implements GenericIBatisDao<T> {

	private static final String STMT_INSERT = ".insert";
	private static final String STMT_UPDATE = ".updateByPrimaryKey";
	private static final String STMT_DELETE = ".deleteByPrimaryKey";
	private static final String STMT_SELECT = ".selectByPrimaryKey";

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.commerceE.dao.impl.GenericIBatisDao#getNAMESPACE()
	 */
	public abstract String getNAMESPACE();

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.commerceE.dao.impl.GenericIBatisDao#insert(T)
	 */
	public int insert(T object) {
		return getSqlSession().insert(getNAMESPACE() + STMT_INSERT, object);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.commerceE.dao.impl.GenericIBatisDao#update(T)
	 */
	public void update(T object) {
		getSqlSession().update(getNAMESPACE() + STMT_UPDATE, object);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.commerceE.dao.impl.GenericIBatisDao#delete(long)
	 */
	public void delete(long id) {
		getSqlSession().update(getNAMESPACE() + STMT_DELETE, id);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.commerceE.dao.impl.GenericIBatisDao#get(long)
	 */
	public T get(long id) {
		return (T) getSqlSession().selectOne(getNAMESPACE() + STMT_SELECT, id);
	}

}
